package net.aaa.hotel.dao.impl;

import net.aaa.hotel.dao.TRuzhudetailDao;
import net.aaa.hotel.entity.TRuzhudetail;
import net.aaa.hotel.util.BaseDB;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class TRuzhudetailDaoImpl implements TRuzhudetailDao {
    @Override
    public int addRuzhuDetail(TRuzhudetail ruzhudetail) {
        String sql = "insert into t_ruzhudetail(idcard,orderid,roomid,uname,tel,indate,rzyj,rzjbr) " +
                "values(?,?,?,?,?,now(),?,?)";
        return BaseDB.update(sql, ruzhudetail.getIdcard(), ruzhudetail.getOrderid(), ruzhudetail.getRoomid(), ruzhudetail.getUname(),
                ruzhudetail.getTel(), ruzhudetail.getRzyj(), ruzhudetail.getRzjbr());
    }

    @Override
    public List<Map> getRuzhuDetailByRoomId(String roomid) {
        String sql = " select r.*,o.leavedate outdate, t.money \n" +
                "from t_ruzhudetail r,t_order o,t_type t \n" +
                "where r.orderid = o.id and o.roomtype = t.id\n" +
                "and o.`status`!=2 and r.`status`!=3 and r.id not in ( \n" +
                "\t select ruzhuid from t_tuifang where ruzhuid is not null) and r.roomid=? ";
        return BaseDB.queryMap(sql, roomid);
    }

    @Override
    public int changeRuzhuDetailStatusBy(Integer id, Integer status) {
        String sql = "update t_ruzhudetail set status=? where id=?";
        return BaseDB.update(sql, status, id);
    }

    @Override
    public int changRuZhuDeatilRoomId(Integer id, Integer roomid) {
        String sql = "update t_ruzhudetail set roomid=? where id=? ";
        return BaseDB.update(sql, roomid, id);
    }
}
